package com.handpay.zztong.hp.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Vector;

import se.krka.kahlua.vm.LuaTable;

import com.handpay.framework.LuaTableUtil;
import com.handpay.zztong.hp.log.HPLog;

public class PurchaseStatus implements Serializable {
	
	private static final long serialVersionUID = -1122576365916220535L;
	private String purchaseType;
	private Double amount;
	private String status;
	private String message;
	private ArrayList<PurchaseEvent> purchaseList = new ArrayList<PurchaseEvent>();
	//	private purchaseEvent [] milestoneDescs;
	private String statusDesc;
	private String purchaseTime;
	private String requestTime;
	
	
	
	public String getPurchaseType() {
		return purchaseType;
	}
	public void setPurchaseType(String purchaseType) {
		this.purchaseType = purchaseType;
	}
	public Double getAmount() {
		return amount;
	}
	public void setAmount(Double amount) {
		this.amount = amount;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public ArrayList<PurchaseEvent> getPurchaseList() {
		return purchaseList;
	}
	public void setPurchaseList(ArrayList<PurchaseEvent> purchaseList) {
		this.purchaseList = purchaseList;
	}
	public String getStatusDesc() {
		return statusDesc;
	}
	public void setStatusDesc(String statusDesc) {
		this.statusDesc = statusDesc;
	}
	public String getPurchaseTime() {
		return purchaseTime;
	}
	public void setPurchaseTime(String purchaseTime) {
		this.purchaseTime = purchaseTime;
	}
	public String getRequestTime() {
		return requestTime;
	}
	public void setRequestTime(String requestTime) {
		this.requestTime = requestTime;
	}
	public static PurchaseStatus generatePurchaseStatus(LuaTable data) {
		PurchaseStatus p = new PurchaseStatus();		
		try {
			p.setPurchaseType((String)data.rawget("purchaseType"));
			p.setAmount((Double) data.rawget("amount"));
			p.setStatus((String)data.rawget("status"));
			p.setMessage((String)data.rawget("message"));
			p.setStatusDesc((String)data.rawget("statusDesc"));
			p.setPurchaseTime((String)data.rawget("purchaseTime"));
			p.setRequestTime((String)data.rawget("requestTime"));
			LuaTable mMilestoneDescs = (LuaTable)data.rawget("milestoneDescs");
			ArrayList<PurchaseEvent> eventList = new ArrayList<PurchaseEvent>();	
			if(null != mMilestoneDescs){
				Vector<LuaTable> dataList = LuaTableUtil.getArray(mMilestoneDescs);
   	 			for(LuaTable table : dataList){
   	 			PurchaseEvent event = PurchaseEvent.generatePurchaseEvent(table);
   	 				if(null != event){
   	 				eventList.add(event);
   	 				}
   	 			}
   	 			p.setPurchaseList(eventList);
			}
//			p.setRequestTime(System.currentTimeMillis());
			return p;
		} catch (Exception e) {
			HPLog.i("PurchaseStatus", "generatePurchaseStatus" ,e);
			return null;
		}
	}
	public static class PurchaseEvent implements Serializable {

		/**
		 * 
		 */
		private static final long serialVersionUID = 990315841303882511L;
		private String eventTime;
		private String eventDesc;
		private String isFinish;
		
		public String getEventTime() {
			return eventTime;
		}
		public void setEventTime(String eventTime) {
			this.eventTime = eventTime;
		}
		public String getEventDesc() {
			return eventDesc;
		}
		public void setEventDesc(String eventDesc) {
			this.eventDesc = eventDesc;
		}
		public String getIsFinish() {
			return isFinish;
		}
		public void setIsFinish(String isFinish) {
			this.isFinish = isFinish;
		}

		public static PurchaseEvent generatePurchaseEvent(LuaTable data) {
			PurchaseEvent event = new PurchaseEvent();
			try {
				
				event.setEventTime((String)data.rawget("eventTime"));
				event.setEventDesc((String) data.rawget("eventDesc"));
				event.setIsFinish((String)data.rawget("isFinish"));
				return event;
			} catch (Exception e) {
				HPLog.i("PurchaseEvent", "generatePurchaseEvent" ,e);
				return null;
			}
		}
	}
}
